﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Rhino.Commons;
using DomainModel.Entities;
using Rhino.Commons.ForTesting;

namespace Tests
{
    [TestFixture]
    public class SportsRepositoryFixture : DatabaseTestFixtureBase
    {
        //private IRepository<Product> productRepository;
        private Product prod;

        [TestFixtureSetUp]
        public void TestFixtureSetUp()
        {
            IntializeNHibernateAndIoC(PersistenceFramework.NHibernate, @"C:\Users\hfranco\Documents\Visual Studio 2008\Projects\SportsStore\Core\Tests\windsor.boo", DatabaseEngine.MsSql2005Express, "SportsStore",
            MappingInfo.From(typeof(Product).Assembly));
            //productRepository = IoC.Resolve<IRepository<Product>>();

            //prod = new Product();
            //prod.Name = "Bat";
            //prod.Price = 25;
            //prod.Category = "Baseball";
            //prod.Description = "Used by Adrian Gonzales";

            //UnitOfWork.CurrentSession.Save(prod);
            //UnitOfWork.Current.TransactionalFlush();
        }

        [SetUp]
        public void SetUp()
        {
            CurrentContext.CreateUnitOfWork();
        }

        [TearDown]
        public void Teardown()
        {
            CurrentContext.DisposeUnitOfWork();
        }

        [Test]
        public void CanSaveProduct()
        {
            var product = new Product();
            product.Name = "Glove";
            product.Price = 15;
            product.Category = "Baseball";
            product.Description = "Worn by Manny";

            UnitOfWork.CurrentSession.Save(product);
            UnitOfWork.Current.TransactionalFlush();

            var fromDB = UnitOfWork.CurrentSession.Get<Product>(product.ProductID);
            Assert.IsNotNull(fromDB);
            Assert.AreEqual(product.Name, fromDB.Name);
        }
    }
}
